package jscinttools.transmission;

import jscinttools.utilities.aidautilities.AidaFactories;
import jscinttools.utilities.aidautilities.AidaFileReader;
import hep.aida.ITree;
import hep.aida.ITreeFactory;
import hep.aida.ITuple;
import hep.aida.ITupleFactory;
import hep.aida.IDataPointSetFactory;
import hep.aida.IDataPointSet;
import java.lang.System;
import java.lang.String;
import java.lang.Double;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import fr.in2p3.ipnl.aidautilities.TupleReader;
import fr.in2p3.ipnl.utilities.fileutilities.HeaderDecapitator;
import jscinttools.transmission.*;
import jscinttools.utilities.aidautilities.AidaFactories;

/**
 *  Generates the Rates calculation
 *
 *@author     Marc-Antoine Verdier
 *@created    19 mai 2011
 */
public class TransTempSweepAnalysis
{
	private String outPath;
	private EventLED[] evtLED;
	private EventLED bckEvtLED;


	/**
	 *  Constructor for the TransTempSweepAnalysis object
	 *
	 *@param  path      Description of the Parameter
	 *@param  files     Description of the Parameter
	 *@param  bckPath   Description of the Parameter
	 *@param  bckFiles  Description of the Parameter
	 *@param  outPath   Description of the Parameter
	 */
	public TransTempSweepAnalysis(String[] path, String[] files, String bckPath, String bckFiles, String outPath)
	{
		this.outPath = outPath;
		int loop = files.length;
		this.evtLED = new EventLED[loop];
		for (int i = 0; i < loop; i++)
		{
			evtLED[i] = new EventLED(path[i], files[i], outPath);
		}
		this.bckEvtLED = new EventLED(bckPath, bckFiles, outPath);
	}


	/**
	 *  Description of the Method
	 *
	 *@param  chans       Description of the Parameter
	 *@param  freqHz      Description of the Parameter
	 *@param  splitTerms  Description of the Parameter
	 *@param  aidaName    Description of the Parameter
	 */
	public void doAnalysisTDC(int[] chans, double freqHz, String[] splitTerms, String aidaName)
	{
		try
		{
			try
			{
				ITree tree = AidaFactories.TREE_FACTORY.createTree(outPath + File.separator + aidaName + ".aida", "xml", ITreeFactory.CREATE);
				TDCRateLED tdcRateLED = new TDCRateLED(evtLED, bckEvtLED, tree);
				tdcRateLED.makeTupleAndDPS(chans, freqHz, splitTerms);
				tree.commit();
				System.out.println("Writting file : " + outPath + File.separator + aidaName + ".aida");
			} catch (FileNotFoundException fnfe)
			{
				System.out.println(fnfe);
			}
		} catch (IOException ioe)
		{
			System.out.println("Problem with aida file: " + ioe);
		}
	}
}

